<?php
#基础函数
include_once('_path.php');
include_once("../includes/init.php");

####变量
#搜索
$do = trim($_GET['do']);
#！！搜索
if ($do == 'search') {
	$word = trim($_GET['word']);
}

#正式的查询语句
$sql = "SELECT am.* FROM admin am WHERE 1 = 1".
iif(strlen($word) > 1, " AND name LIKE '%$word%'").
" ORDER BY id DESC";

#正式查询
$rs = $database->queryArray($sql);

add_log('show', 'admin');

$css = array('index', 'table');
$js = array();
include_once("../layout/_header.php");
?>
<div id="path">
	<ul>
		<li><a href="<?php echo _CONST_WEB_URL ?>"><?php echo _CONST_WEB_NAME?></a></li>
		<li><a href="<?php echo _CONST_BACKEND_URL ?>">Backend</a></li>
		<li>Admin</li>
	</ul>
	<a href="<?php echo _CONST_BACKEND_URL?>logout.php" class="r" style="margin:2px 10px"><span class="logout">Logout</span></a>
</div>

<div id="content">
	<ul id="submenu">
		<li class="current"><a href="./" class="button"><span class="list">List</span></a></li>
		<li ><a href="admin_edit.php?func=add" class="button"><span class="add">New</span></a></li>
	</ul>
   <span style="margin:7px 10px 2px 50px;" class="l">Current User:<?php echo $_SESSION['bname']?>&nbsp;&nbsp;<?php echo gmdate('D M j, Y h:ia T', _CONST_TIMENOW) ?></span>

	<div style="float:right;margin-right:10px;">
		<form>
		Name <input type="text" name="word" value="<?php echo htmlspecialchars($word) ?>" size="20" />
		<input type="submit" name="do" value="search" class="button">
		</form>
	</div>
	<?php
	if (sizeof($rs) > 0){
	?>
	<div class="cr"></div>
	<form action="update_admin.php" name="form" id="form" method="post">
	<input type="hidden" name="type" value="" />
	<table class="list" cellspacing="0">
		<tr>
			<th class="no">&nbsp;</th>
			<th class="no">ID</a></th>
			<th width="100%" class="no">Name</th>
			<th class="no">Email</th>
			<th class="no">LastTime</a></th>
			<th class="no">LastIP</a></th>
			<th class="no">Status</a></th>
			<th class="no">&nbsp;</th>
		</tr>
		<?php
		for($i=0;$i<sizeof($rs);$i++) {
			$r = $rs[$i];
			?>
			<tr>
				<td class="no"><input type="checkbox" name="admin_ids[]" value="<?php echo $r['id'] ?>"></td>
				<td class="no rt"><?php echo $r['id'] ?></td>
				<td class="no"><?php echo $r['name'] ?></td>
				<td class="no"><?php echo $r['email'] ?></td>
				<td class="no"><?php echo gmdate('m/d Y H:i:s', $r['lasttime']) ?></td>
				<td class="no"><?php echo $r['lastip'] ?></td>
				<td class="no c"><span class="<?php echo iif($r['status'], "lock", "unlock") ?>"></span></td>
				<td class="action no">
					<a href="admin_edit.php?func=edit&admin_id=<?php echo $r['id'] ?>" class="button">
						<img src="<?php echo _CONST_BACKEND_URL ?>media/edit.png" />
						Edit
					</a>
				</td>
			</tr>
			<?php
		} // while ($r = $st->get_row())
		?>
		<tr><td colspan="8" class="action" style="padding:5px;">
			<a href="javascript:checkAll('admin_ids[]')" class="button"><span class="on">checkAll</span></a> &nbsp;
			<a href="javascript:clearAll('admin_ids[]')" class="button"><span class="off">clearAll</span></a> &nbsp; &nbsp; &nbsp; &nbsp;
			<a href="javascript:document.form.type.value='lock';document.form.submit();" class="button"><span class="lock">Lock</span></a> &nbsp;
			<a href="javascript:document.form.type.value='unlock';document.form.submit();" class="button"><span class="unlock">Unlock</span></a> &nbsp; &nbsp; &nbsp; &nbsp;
		</td></tr>
	</table>
	</form>
	<?php
	}else{
	?><div class="border cr">No Record</div><?php
	}?>
	</div>
<?php
include_once("../layout/_footer.php");
?>